import os
import numpy as np
import pandas as pd
from pyecharts import Bar


# Create your ana here.


class ChipotleNan:

    def __init__(self):
        self.csv_name = 'D:\show\six\Anaxls\datase\chips.csv'

        self.df = pd.read_csv(self.csv_name, sep='\t')

    def bar(self, axis0, axis1, name='test', table_name='test1'):
        bar = Bar(name)

        bar.add("商家A", axis0, axis1, is_label_show=True, is_datazoom_show=True)

        return bar

    def series_to_bar(self, series, name='test', table_name='test1'):
        bar = Bar(name)
        axis0 = series.index
        axis1 = np.round(series.values.ravel(), 1)

        bar.add("商家A", axis0, axis1, is_label_show=True, is_datazoom_show=True)

        return bar

    def how_many_are_sold_per_item(self):
        df1 = self.df.groupby('item_name').sum()

        df1.drop('order_id', axis=1, inplace=True)

        return df1

    def bar_how_many_are_sold_per_item(self):
        # chipo = ana.ChipotleNan()

        info = self.how_many_are_sold_per_item()

        # bar = self.bar(info.index, info.quantity)

        bar = self.series_to_bar(info)

        return bar

    def how_much_are_sold_per_item(self):
        ipr = self.df.quantity * (self.df.item_price.str.replace('$', '').astype('float64'))
        df1 = self.df.copy()
        df1['ipr'] = ipr
        df1_group = df1.groupby('item_name').sum()

        df1_group = df1_group.drop('order_id', axis=1)
        df1_group = df1_group.drop('quantity', axis=1)

        return df1_group

    def bar_how_much_are_sold_per_item(self):
        info = self.how_much_are_sold_per_item()

        bar = self.series_to_bar(info, '每种商品销售金额')

        return bar












































